<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%--获取当前时间--%>
<%@ page import="java.sql.*" %>
<jsp:useBean id="now" class="java.util.Date" scope="page"/>
<fmt:formatDate var="nowTime" value="${now}" pattern="yyyy-MM-dd HH:mm:ss"/>
<!DOCTYPE html>

<html>


<%

    //state =4 简单查询 5复合条件查询
    //处理复合查询代码
    Integer id = Integer.valueOf(request.getParameter("id"));

    //判断查询
    String sql = "SELECT  * from car where status =22 and id="+id;

 Integer userid = Integer.valueOf(session.getAttribute("id").toString());










    Boolean isCollection = false;
    String isCollectionSql = "select * from collection where userid="+userid+" and carid="+id;
//    //增加收藏
    String addCollection = "/view/customer/customer/collection/doCollectionExcute.jsp?state=1&carid="+id+"&userid="+userid;
//    //取消收藏
    String removeCollection = "/view/customer/customer/collection/doCollectionExcute.jsp?state=3&carid="+id+"&userid="+userid;


    String number = null;

    number =  null;
    String name =  null;
    String images = null;
    String price =  null;
    String introduction = null;
    String address =  null;
    Integer age =  null;
    String createtime =  null;
    String identity = null;
    String phone =  null;;
    String username =  null;;
    Integer collection =  null;
    Integer gearboxId = null;
    String gearbox = null;
    Integer statusId = null;
    String status = null;

    //jdbc:mysql

    System.out.println("执行了sql =====》"+sql);
    String url = "jdbc:mysql://localhost:3306/carxianyu";
    String user = "root";
    String pwd = "root";
    Class.forName("com.mysql.jdbc.Driver");//加载驱动
    Connection conn = DriverManager.getConnection("jdbc:mysql://43.142.239.28:13307/carxianyu?useUnicode=true&characterEncoding=UTF-8&serverTimeZone=UTC","root","root");
    PreparedStatement a = conn.prepareStatement(sql);
    ResultSet rs = a.executeQuery();


    while(rs.next()) {

        //为列表参数初始化
        identity =rs.getString("identity");
        number = rs.getString("number");

        name = rs.getString("name");
        images = rs.getString("images");
      price = rs.getString("price");
        introduction = rs.getString("introduction");
     address = rs.getString("address");
        age = Integer.valueOf(rs.getString("age"));
         createtime = rs.getString("createtime");
       identity = rs.getString("identity");
      phone = rs.getString("phone");
        username = rs.getString("username");
       collection = Integer.valueOf(rs.getString("collection"));
      gearboxId = Integer.valueOf(rs.getString("gearbox"));



        if (gearboxId == 11) {
            gearbox = "手动档";
        } else {
            gearbox = "自动档";
        }




    }

    rs.close();;
    a.close();;
    conn.close();

    Class.forName("com.mysql.jdbc.Driver");//加载驱动
    Connection conn2 = DriverManager.getConnection("jdbc:mysql://43.142.239.28:13307/carxianyu?useUnicode=true&characterEncoding=UTF-8&serverTimeZone=UTC","root","root");
    PreparedStatement a2 = conn2.prepareStatement(isCollectionSql);
    ResultSet rs2 = a2.executeQuery();
    System.out.println("执行sql ==》"+isCollectionSql);
    while (rs2.next()){
        isCollection = true;
        System.out.println("是否收藏=>"+isCollection);
    }

%>



<head>
    <meta charset="utf-8">
    <title>康康的宠物领养平台-详情显示</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/static/layui/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctx}/static/layui/style/template.css" media="all">
    <script src="${ctx}/static/layui/layui.js"></script>
    <link rel="shortcut icon" href="${ctx}/static/favicon.png" type="image/x-icon"/>
    <link rel="icon" href="${ctx}/static/favicon.png" type="image/gif">
</head>
<body>
<!--导航条 start-->
<jsp:include page="/head.jsp"/>

<!--导航条 end-->

<div class="layui-container">
    <fieldset class="layui-elem-field layui-field-title site-title" style="text-align: center;margin: 30px">
        <!--标题-->
        <legend><a name="compatibility"><%=name%> 《<%=number%> 》</a></legend>
    </fieldset>

    <div class="layui-row" style="background: #fff;">
        <div style="height: 10px;"></div>
        <div class="layui-elem-quote" style="margin: 20px;">
            <p style="font-size: 18px;">折扣价：<%=price%>  </p>
            <p style="font-size: 18px;">车龄：<%=age%>  </p>

            <p style="font-size: 18px;">折扣价：<%=price%>  </p>

            <p style="font-size: 18px;">车主：<%=username%>  </p>
            <p style="font-size: 18px;">车主电话：<%=phone%>  </p>

            <p style="font-size: 18px;">收藏人数：<%=collection%>
                &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;

                <c:if test="${sessionScope.depart == 22}">

                        <c:if test="<%=!isCollection%>">
                        <a href="${ctx}<%=addCollection%>" class="layui-btn layui-btn-danger layui-btn-sm">点击收藏</a>
                        </c:if>
                        <c:if test="<%=isCollection%>">
                            <a  class="layui-btn layui-btn-danger layui-btn-sm">已收藏</a> </p>
                        </c:if>
               </c:if>


            <p style="font-size: 18px;">引擎：<%=gearbox%>  </p>
            <p style="font-size: 18px;">三方证明：<%=identity%>  </p>

        </div>

        <div class="layui-col-md12" style="text-align: center">
            <div class="contentshow"><%=introduction%> </div>
            <style>
                .contentshow {
                    font-size: 20px;
                    line-height: 2em;
                    text-indent: 2em;
                }
            </style>
        </div>
        <div class="layui-col-md12" style="text-align: center;margin-top: 50px;">
            <img src="<%=images%> " style="width: 60%;border: 1px solid #cecece;padding: 20px;">


        </div>
        <div class="layui-col-md12">

            <div class="layui-row">
                <div class="layui-col-md12" style="background: #eee;border-radius:20px; ">
                    <form class="layui-form layui-form-pane" action="${ctx}/commentinfoSubmit" method="post">
                        <input type="hidden" name="tid" value="${datainfo.id}">
                        <input type="hidden" name="username" value="${sessionScope.loginUserinfo.name}">
                        <input type="hidden" name="addtime" value="${nowTime}">
                        <input type="hidden" name="picurl" value="${sessionScope.loginUserinfo.picurl}">
                        <input type="hidden" name="likenum" value="0">

                    </form>
                </div>

            </div>

        </div>
    </div>

</div>
<div style="height: 50px;"></div>


<script>
    var userid = "${sessionScope.loginUserinfo.id}"; //用户编号
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    var $;
    var layer;
    var element;
    var form;
    layui.use(['element', 'layer', 'jquery', 'form', 'laydate', 'layedit'], function () {
        element = layui.element;
        layer = layui.layer;
        $ = layui.jquery;
        form = layui.form;
        var laydate = layui.laydate;


        //…
    });
</script>

<style>
    .comment {
        margin-top: 4%;
        margin-left: 14%;
        padding: 2%;
        width: 68%;
        background-color: #ececec;
        border: 1px dashed #888;
        border-radius: 1em;
        position: relative;
        display: block;
        text-align: left;
    }

    .comment:hover img {
        border-radius: 1em;
        border: 2px solid #888;
    }

    .comment:hover {
        background-color: #eee;
    }

    .comment img {
        position: absolute;
        top: -1%;
        left: -10%;
        border-radius: 2em;
        border: 2px solid #888;
        width: 60px;
        height: 60px;
    }

    .comment p {
        text-indent: 2em;
        margin-top: 0.4%;
    }

    .comment span {
        position: absolute;
        top: 10%;
        right: 4%;
        font-size: 0.9em;
        font-weight: bold;
        color: #444
    }

    .comment .name {
        color: black;
        font-weight: bold;
        text-decoration: none;
    }

    .comment .name:hover {
        text-decoration: underline;
    }

    .comment .up {
        color: #555;
        text-decoration: none;
        position: absolute;
        bottom: 4%;
        right: 8%;
    }

    .comment .up:hover {
        color: #000;
    }
</style>
</body>
</html>
